/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module settlbat.c - Functions to save and print the batch history report|
   @end

$Log: /SoftPay/SPK2SIM/Source/Batch/settlbat.c $
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#include <project.h>

#ifdef BATCH_DEFINED

#define VSSTLBAT_C

#include <aclconio.h>
#include <stdio.h>
#include <stdlib.h>
#include <ascii.h>
#include <errno.h>
#include <dbmgr.h>
#include <string.h>
#include <message.h>
#include <aclstr.h>
#include <iso8583.h>
#include <amexhost.h>


/** /#define DEBUG_VSSTLBAT*/
#ifdef DEBUG_VSSTLBAT
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <tran.h>
#include <util.h>
#include <mem.h>
#include <gds.h>
#include <msg.h>
#include <msgfuncs.h>
#include <msgclrk.h>
#include <msgshf.h>
#include <udt.h>
#include <cdt.h>
#include <cst.h>
#include <hdt.h>
#include <bdt.h>
#include <opt.h>
#include <tct.h>
#include <trt.h>
#include <sdt.h>
#include <udt.h>
#include <confio.h>
#include <form.h>
#include <revutl.h>
#include <test.h>
#include <spdebug.h>
#include <ui.h>
#include <entry.h>
#include <operate.h>
#include <pbatch.h>
#include <mdlfuncs.h>
#include <accum.h>
#include <table.h>
#include <funcids.h>
#include <autosttl.h>
#include <settle.h>
#include <settlbat.h>
#include <review.h>
#include <batmsg.h>
#include <mht.h>
#include <pfr.h>
#include <codesec.h>
#include <logo.h>
#include <mit.h>
#include <merch.h>
#include <multilng.h>
#include <oper.h>
#include <date.h>
#include <tblutil.h>
#include <file.h>

/*********************************************************************************************
* @func static void | vdGetSettFname |
*
*       Loads the corresponding batch file name.
*
* @parm char * | pchBFName |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

static void vdGetSettFName(char* pchBFName) {
    //  TRANSACTION_OBJECT *pobTran;

    //  pobTran = pstGet_pobTran();

    if (fGetDemoMode() == VS_TRUE)
        sprintf(pchBFName, "DSTL%02d%02d", inGetBatchIndex(), inGetMerchantNum());
    else
        sprintf(pchBFName, "SETT%02d%02d", inGetBatchIndex(), inGetMerchantNum());
}

/*********************************************************************************************
* @func static int | inOpenSett |
*
*       Opens/Creates the desired Sett batch file.
*       The filename MUST NOT contain a file extension. Returns the handle
*       to index file vssett.h - defines the BUYPASS key structure.
*
* @parm DB_FILE *   | psrDBFPtr |
* @parm char *      | pchFName |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inOpenSett(DB_FILE* psrDBFPtr,char* pchFName) {
    int inRetVal;

    /** /pdebug(("--inOpenSett--"));*/

    inRetVal = db_open(psrDBFPtr, pchFName, SIZE_SETT_KEY, O_RDWR);

    if (inRetVal < 0) /* If file is non-existant, create it */
        if (errno == ENOENT)
            inRetVal = db_open(psrDBFPtr, pchFName, SIZE_SETT_KEY, (O_CREAT | O_RDWR));

    if (inRetVal < 0)
        return(VS_ERR);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static int | inCloseSett |
*
*       Closes the batch file.
*       Calling database manager opens 2 files.
*
* @parm DB_FILE * | psrDBFPtr |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inCloseSett(DB_FILE* psrDBFPtr) {
    /** /pdebug(("--inCloseSett--"));*/

    if (db_close(psrDBFPtr) > 0)
        return(VS_SUCCESS);

    return(VS_ERR);
}

/*********************************************************************************************
* @func static int | inClearSett |
*
*       Delete all the sett batch records after the batch close transaction.
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inClearSett() {
    char pchBFName[FILENAME_SIZE + 1];
    DB_FILE srDBFile;

    /** /pdebug(("--inClearSett--"));*/

    vdGetSettFName(pchBFName);

    if (db_open(&srDBFile, pchBFName, SIZE_SETT_KEY, (O_TRUNC | O_CREAT | O_RDWR)) < 0)
        return(VS_ERR);

    if (db_close(&srDBFile) < 0)
        return(VS_ERR);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static int | inAddSettRec |
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm char *  | szFileName |
* @parm DB_FILE *   | psrDBFPtr |
* @parm long    | lnRecNum |
* @parm SETT_REC *  | psrSRec |
* @parm SETT_KEY *  | psrSKey |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inAddSettRec(TRANSACTION_OBJECT* pobTran,char* szFileName,DB_FILE* psrDBFPtr,long  lnRecNum,SETT_REC* psrSRec,SETT_KEY* psrSKey) {
    /** /pdebug(("--inAddSettRec--"));*/

    if (inOpenSett(psrDBFPtr, szFileName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    if (db_write(psrDBFPtr, psrSKey, (char *) psrSRec, SIZE_SETT_REC, lnRecNum) < 0) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        inCloseSett(psrDBFPtr);
        return(VS_ERR);
    }

    if (inCloseSett(psrDBFPtr) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static void | vdFormSettKey |
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm SETT_KEY *  | psrSKey |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static void vdFormSettKey(TRANSACTION_OBJECT* pobTran,SETT_KEY* psrSKey) {
    /** /pdebug(("--vdFormSettKey--"));*/

    strlcpy(psrSKey->szDate, pobTran->szSettDate, DATE_SIZE);
    strlcpy(psrSKey->szBatchNum, pobTran->szBatchNum, BATCH_NUM_SIZE);
}

/*********************************************************************************************
* @func int | inPutSettRec |
*
*       Forms the settlement batch data, puts it to the appropriate
*       batch file.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm SETT_REC *  | psrSRec |
* @parm SETT_KEY *  | psrSKey |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inPutSettRec(TRANSACTION_OBJECT* pobTran,SETT_REC* psrSRec,SETT_KEY* psrSKey) {
    char szSettFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    int inResult;

    /** /pdebug(("--inPutSettRec--"));*/

    vdFormSettKey(pobTran, psrSKey);

    /* Form the batch record */
    strlcpy(psrSRec->szTime, pobTran->szSettTime, DATE_SIZE);
    strlcpy(psrSRec->szDate, pobTran->szSettDate, DATE_SIZE);
    strlcpy(psrSRec->szBatchNum, pobTran->szBatchNum, BATCH_NUM_SIZE);
    vdGGRespMsg(psrSRec->szSettleResp);

    memcpy((char *) &(psrSRec->srTerminal), (char *) &(srRcpt.unFrm.srSubTotal.srTerm), sizeof(TOTALS_FORM));

    vdGetSettFName(szSettFileName);
    if ((inResult = inAddSettRec(pobTran, szSettFileName, &srDBFPtr, DB_APPEND, psrSRec, psrSKey)) != VS_SUCCESS)
        return(inResult);

    if ((inResult = inDeleteEighthBatRec()) != VS_SUCCESS)
        return(inResult);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static int | inGetSettRec |
*
*       Retrieve the settlement batch record from the appropriate file.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm long    | lnRecNum |
* @parm SETT_REC *  | psrSRec |
* @parm SETT_KEY *  | psrSKey |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inGetSettRec(TRANSACTION_OBJECT* pobTran,long lnRecNum,SETT_REC* psrSRec,SETT_KEY* psrSKey) {
    DB_FILE srDBFPtr;
    char szBFName[FILENAME_SIZE + 1];

    /** /pdebug(("--inGetSettRec--"));*/

    vdGetSettFName(szBFName);
    if (inOpenSett(&srDBFPtr, szBFName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }
    if (db_read(&srDBFPtr, psrSKey, (char *) psrSRec, SIZE_SETT_REC, lnRecNum) != (int) SIZE_SETT_REC) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        inCloseSett(&srDBFPtr);
        return(VS_ERR);
    }
    if (inCloseSett(&srDBFPtr) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static int | inSettCompFn |
*
*       This function will be called by the following function, as
*       one of the parameters of the db_seek_key() function.
*
* @parm SETT_KEY *  | psrSKey |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inSettCompFn(SETT_KEY* psrSKey,SETT_SKEY* MatchKey) {
    int inRetVal = VS_ERR;

    /** /pdebug (("--inSettCompFn--%d",MatchKey->inKeyIdx));*/

    /* Search on Batch # */
    if (MatchKey->inKeyIdx == KEY_BATCH_NUM) {
        if (atol(MatchKey->srSettKey.szBatchNum) == atol(psrSKey->szBatchNum)) {
            /** /pdebug (("KEY_BATCH_NUM %ld/%ld",
                atol(MatchKey->srSettKey.szBatchNum),
                atol(psrSKey->szBatchNum));*/
            inRetVal = VS_SUCCESS;
        }
    }

    /* Search on Date */
    if (MatchKey->inKeyIdx == KEY_SETT_DATE) {
        if (strcmp(MatchKey->srSettKey.szDate, psrSKey->szDate) == 0) {
            /** /pdebug (("KEY_SETT_DATE %s/%s",
                atol(MatchKey->srSettKey.szDate),
                atol(psrSKey->szDate));*/
            inRetVal = VS_SUCCESS;
        }
    }

    /** /pdebug(("inRetVal = %d",inRetVal));*/
    return(inRetVal);
}

/*********************************************************************************************
* @func static int | inKeySettFindRead |
*
*       Before Calling this function ensure the following:
*           1. Fill the srBatchKey struct with relevant values
*           2. Set the global 'inSearchIndex' variable to the search
*           field index.
*
* @parm DB_FILE *   | psrDBFPtr |
* @parm SETT_REC *  | psrSRec |
* @parm SETT_KEY *  | psrSKey |
* @parm int         | inKeyIdx |
* @parm long *      | plnRecNum |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inKeySettFindRead(DB_FILE* psrDBFPtr,SETT_REC* psrSRec,SETT_KEY* psrSKey,int inKeyIdx,long* plnRecNum) {
    long lnRetVal;
    long lnDBWhat = DB_FIRST;
    SETT_SKEY srSETT_SKEY;

    /** /(("--inKeySettFindRead--"));*/

    /* Load Batch Search Key Structure */
    srSETT_SKEY.compare_func = inSettCompFn;
    srSETT_SKEY.inKeyIdx = inKeyIdx;
    memcpy(&srSETT_SKEY.srSettKey, psrSKey, SIZE_SETT_KEY);

    do {
        lnRetVal = db_seek_key(psrDBFPtr, psrSKey, &srSETT_SKEY, lnDBWhat, plnRecNum);

        lnDBWhat = DB_NEXT;
        /* Match Found, Read the Record */
        if (lnRetVal == 1L) {
            if (db_read(psrDBFPtr, psrSKey, (char *) psrSRec, SIZE_SETT_REC, *plnRecNum) == (int) SIZE_SETT_REC)
                return(VS_SUCCESS);
            else
                return(VS_ERR);
        } else if (lnRetVal == 0L)
            return(VS_ERR);
    } while (1);
}

/*********************************************************************************************
* @func static int | inGetKeySettRec |
*
*       The outer layer fills the batch key, which field of the key is
*       indicated by inKeyIdx, this function reads the corresponding
*       record and key and returns back the batch record number. On
*       error it returns VS_ERR. Opening and closing of the batch
*       record is done by this layer itself.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm SETT_REC *              | psrSRec |
* @parm SETT_KEY *              | psrSKey |
* @parm int                     | inKeyIdx |
* @parm long *                  | plnRecNum |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inGetKeySettRec(TRANSACTION_OBJECT* pobTran,SETT_REC* psrSRec,SETT_KEY* psrSKey,int inKeyIdx,long* plnRecNum) {
    DB_FILE srDBFPtr;
    char szBFName[FILENAME_SIZE + 1];

    /** /pdebug(("--inGetKeySettRec--"));*/

    vdGetSettFName(szBFName);

    if (inOpenSett(&srDBFPtr, szBFName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    if (inKeySettFindRead(&srDBFPtr, psrSRec, psrSKey, inKeyIdx, plnRecNum) != VS_SUCCESS) {
        inCloseSett(&srDBFPtr);
        vdSGErrorMessage(INVALID_INV_NUM_ERR_MSG);
        return(VS_ERR);
    }

    if (inCloseSett(&srDBFPtr) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func long | lnGetSettRecCnt |
*
*       Gets the count of record in the normal batch file.
*       NOTE: Host index should be set to the appropriate value.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values
*
* @flag long        |   - the record number
*                       - VS_ERR
* @end
**********************************************************************************************/

long lnGetSettRecCnt() {
    long lnRecCnt = 0L;
    DB_FILE srDBFile;
    char szBFName[FILENAME_SIZE + 1];

    /** /(("--lnGetSettRecCnt--"));*/

    vdGetSettFName(szBFName);
    if (db_open(&srDBFile, szBFName, SIZE_SETT_KEY, O_RDWR) < 0)
        return(lnRecCnt);

    /* Seek return is the number of records */
    lnRecCnt = db_seek_record(&srDBFile, 0L, SEEK_END);
    /** /pdebug(("lnRecCnt = %ld", lnRecCnt));*/

    if ((db_close(&srDBFile) < 0) || (lnRecCnt < 0))
        return((long) VS_ERR);

    return(lnRecCnt);
}

/*********************************************************************************************
* @func int | inLoadSettRec |
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm SETT_REC *              | psrLocSRec |
* @parm SETT_KEY *              | psrLocSKey |
* @parm long                    | lnRecNum |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inLoadSettRec(TRANSACTION_OBJECT* pobTran,SETT_REC* psrLocSRec,SETT_KEY* psrLocSKey,long lnRecNum) {
    /** /pdebug(("--inLoadSettRec--"));*/

    if (inGetSettRec(pobTran, lnRecNum, psrLocSRec, psrLocSKey) != VS_SUCCESS)
        return(VS_ERR);
    memcpy((char *) &(srRcpt.unFrm.srSubTotal.srTerm), (char *) &(psrLocSRec->srTerminal), sizeof(TOTALS_FORM));
    /* Set GDS Variables for use in Print */
    strlcpy(pobTran->szSettTime, psrLocSRec->szTime, DATE_SIZE);
    strlcpy(pobTran->szSettDate, psrLocSRec->szDate, DATE_SIZE);
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inGetBatchNumSettRec |
*
*       Loads a sett batch record based on batch number.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm SETT_REC *              | psrLocSRec |
* @parm SETT_KEY *              | psrLocSKey |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inGetBatchNumSettRec(TRANSACTION_OBJECT* pobTran,SETT_REC* psrLocSRec,SETT_KEY* psrLocSKey) {
    long lnRecNum;

    /** /pdebug(("--inGetBatchNumSettRec--"));*/
    strlcpy(psrLocSKey->szBatchNum, pobTran->szBatchNum, BATCH_NUM_SIZE);

    if (inGetKeySettRec(pobTran, psrLocSRec, psrLocSKey, KEY_BATCH_NUM, &lnRecNum) != VS_SUCCESS) {
        vdSGErrorMessage(INVALID_INV_NUM_ERR_MSG);
        return(VS_ERR);
    }

    memcpy((char *) &(srRcpt.unFrm.srSubTotal.srTerm), (char *) &(psrLocSRec->srTerminal), sizeof(TOTALS_FORM));
    /* Set GDS Variables for use in Print */
    strlcpy(pobTran->szSettTime, psrLocSRec->szTime, DATE_SIZE);
    strlcpy(pobTran->szSettDate, psrLocSRec->szDate, DATE_SIZE);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inGetDateSettRec |
*
*       Loads a sett batch record based on date.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm SETT_REC *              | psrLocSRec |
* @parm SETT_KEY *              | psrLocSKey |
* @parm long *                  | plnRecNum |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inGetDateSettRec(TRANSACTION_OBJECT* pobTran,SETT_REC* psrLocSRec,SETT_KEY* psrLocSKey,long* plnRecNum) {
    /** /pdebug(("--inGetDateSettRec--"));*/
    strlcpy(psrLocSKey->szDate, pobTran->szSettDate, DATE_SIZE);

    if (inGetKeySettRec(pobTran, psrLocSRec, psrLocSKey, KEY_SETT_DATE, plnRecNum) != VS_SUCCESS) {
        vdSGErrorMessage(INVALID_INV_NUM_ERR_MSG);
        return(VS_ERR);
    }

    memcpy((char *) &(srRcpt.unFrm.srSubTotal.srTerm), (char *) &(psrLocSRec->srTerminal), sizeof(TOTALS_FORM));
    /* Set GDS Variables for use in Print */
    strlcpy(pobTran->szSettTime, psrLocSRec->szTime, DATE_SIZE);
    strlcpy(pobTran->szSettDate, psrLocSRec->szDate, DATE_SIZE);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static int | inDeleteEighthBatRec |
*
*       Deletes a sett batch record to retain only 7 records for each host.
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inDeleteEighthBatRec() {
    DB_FILE srDBFPtr;
    char szBFName[FILENAME_SIZE + 1];

    /** /pdebug(("--inDeleteEighthBatRec--"));*/

    /* Get batch file name */
    vdGetSettFName(szBFName);

    if (lnGetSettRecCnt() <= MAX_SETT_CNT)
        return (VS_SUCCESS);

    if (inOpenSett(&srDBFPtr, szBFName) != VS_SUCCESS)
        return(VS_ERR);
    if (db_delete(&srDBFPtr, 0L, 1L) < 0)
        return(VS_ERR);
    if (inCloseSett(&srDBFPtr) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static VS_BOOL | fSettEmpty |
*
*       Finds the batch file name and check the batch file is empty for the
*       current host number. The parameter decides whether it is a offline
*       or online batch
*       NB: Assumption HDT is loaded before this function is called
*
* @rdesc Return values.
*
* @flag VS_BOOL    |    - VS_TRUE,      If the batch is EMPTY  or DOES NOT exist.
*                       - VS_FALSE,     If batch exists and NOT EMPTY.
* @end
**********************************************************************************************/

static VS_BOOL fSettEmpty() {
    char szBFName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;

    /** /pdebug(("--fSettEmpty--"));*/

    vdGetSettFName(szBFName);

    if (db_open(&srDBFPtr, szBFName, SIZE_SETT_KEY, O_RDWR) < 0)
        return(VS_TRUE);

    db_close(&srDBFPtr);

    strcat(szBFName, DAT_SUFFIX); /* Now verify whether file contains ZERO bytes*/
    if ((lnGetFileSize(szBFName) <= 0))
        return(VS_TRUE);

    return(VS_FALSE);
}

/*********************************************************************************************
* @func int | inSettleOperation |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inSettleOperation(TRANSACTION_OBJECT* pobTran) {
    int inCnt,
    inResult,
    inResultSum = 0;
    long lnResult;
    char szDummyMessage[MESSAGE_SIZE + 1];
    char szMerchantName[MESSAGE_SIZE + 1];
    char szHostName[HOST_NAME_SIZE + 1];
    char szEmptyStr[2];
    int inHosts = MAX_HOSTS;
    int inSettleType;
    int inMerchs = inGetMITTotRecs();
    int inStart,
    inStop,
    inNumberOfMerchants,
    inMerch = 0;
    VS_BOOL fSettleMerch[MAX_MERCHS + 1];


    /* Set power failure recovery state */
    inPFRStateStoreAll(PFR_BEGIN_SETTLEMENT, pobTran, 1, 1);

    /**/pdebug(("--inSettleOperation--"));/**/

    if (fGetDemoMode() && !fGetTrainSettle()) {
        vdDisplayNoSettleMsg(TRAINING_DEMO_MODE_MSG21);
        /* Set power failure recovery state */
        inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
        return(VS_ERR);
    }

    if (fChkAllHostBatches(pobTran)) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    /* determine how many merchants should be settled */
    inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt());
    if (inNumberOfMerchants == inMerchs) {
        inStart = 1;
        inStop = inMerchs;
    } else if (inNumberOfMerchants == 1) {
        inStart = inGetMerchantNum();
        inStop = inGetMerchantNum();
    } else {
        inStart = 1;
        inStop = 0;
    }
    /**/pdebug(("inStart = %d, inStop = %d", inStart, inStop));/**/

    /* loop for selected merchant(s) */
    for (inMerch = inStart; inMerch <= inStop; inMerch++) {
        if (inLoadMITRec(inMerch - 1) != VS_SUCCESS) {
            /**/pdebug(("inLoadMITRec"));/**/
            /* Set power failure recovery state */
            inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
            return(VS_ERR);
        }

        if ((inResult = inSettleOpenTabs(pobTran)) != VS_SUCCESS) {
            /**/pdebug(("inSettleOpenTabs"));/**/
            /* Set power failure recovery state */
            inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
            if (inResult == VS_ESCAPE) {
                fSettleMerch[inMerch] = VS_FALSE; // do not settle this merchant
                continue;
            } else
                return(VS_ERR);
        } else
            fSettleMerch[inMerch] = VS_TRUE;


        /*
         *      Settle all hosts
         */
        /* ====================================================================*/
        for (inCnt = 0; inCnt < inHosts; inCnt++) {
            if (!fIsIndependentBatch(inCnt))
                continue;


            //vdDisplayMessageFromFile( CONFIRM_MSG, STATUS_MSG);
            //lw1start
            //vdGetMessageFromFile( CONFIRM_MSG15, szDummyMessage);

            //vdGetMessageFromFile( EMPTY_STR_ERR_MSG, szEmptyStr);
            //strcat(szDummyMessage,szEmptyStr);
            //lw1end

            //          vdSetHostHandle(inCnt);
            if ((inResult = inLoadDefaultHost(inCnt)) != VS_SUCCESS) {
                /**/pdebug(("inLoadDefaultHost"));/**/
                /* Set power failure recovery state */
                inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
                return(inResult);
            }
            if ((inResult = inLoadDefaultCurrency(pobTran)) != VS_SUCCESS) {
                /**/pdebug(("inLoadDefaultCurrency"));/**/
                /* Set power failure recovery state */
                inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
                return(inResult);
            }
            //lw1start
            vdGetMessageFromFile(CONFIRM_MSG15, szDummyMessage);

            vdGetMessageFromFile(EMPTY_STR_ERR_MSG, szEmptyStr);
            strcat(szDummyMessage, szEmptyStr);
            //lw1end
            strcpy(szHostName, szGetHostName());

            lnResult = lnProceedWithSettlement(pobTran);
            if (lnResult == (long) VS_SUCCESS) {
                vdClearNonTitleLines();
                if (inStop > inStart) {
                    strcpy(szMerchantName, szGetMerchantText());
                    if (getgrid() == 0)
                        vdDisplayDataStr(szMerchantName, (obDisp.inTitleLine + 1), NO_CLEAR, ML_CENTER);
                    else
                        vdDispStrCentered(szMerchantName, (obDisp.inTitleLine + 1), NO_CLEAR);
                }
                if (getgrid() == 0) {
                    vdDisplayStatusString(szDummyMessage);
                    vdDisplayDataStr(szHostName, (obDisp.inStatusLine * 2), CLR_EOL, ML_RIGHT);
                } else {
                    strcat(szDummyMessage, szHostName);
                    /*lw1 only display if Confirm Settle is enabled*/
                    inSettleType = inGetSettlementType();

                    if (inSettleType > 0)
                        vdDisplayStatusString(szDummyMessage);
                }
                vdDelay(PROMPT_DELAY);
                if ((inResult = inConfirmSettle(pobTran)) != VS_SUCCESS) {
                    /* Set power failure recovery state */
                    inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
                    return(inResult);
                }
            } else if (lnResult == BATCH_EMPTY_MSG) {
                //vdDisplayMessageFromFile( SKIP_MSG, WARNING_MSG);
            } else
                inResultSum++;
            vdCloseDCBatch(pobTran);
        }

        /* ==================================================================== */
    } /* merchant loop */


    for (inMerch = inStart; inMerch <= inStop; inMerch++) {
        /**/pdebug(("inMerch = %d", inMerch));/**/
        if (fSettleMerch[inMerch] == VS_FALSE)
            continue;

        if (inLoadMITRec(inMerch - 1) != VS_SUCCESS) {
            /**/pdebug(("inLoadMITRec"));/**/
            /* Set power failure recovery state */
            inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
            return(VS_ERR);
        }

        vdClearNonTitleLines();
        if (inStop > inStart) {
            strlcpy(szMerchantName, szGetMerchantText(), MESSAGE_SIZE);
            if (getgrid() == 0)
                vdDisplayDataStr(szMerchantName, (obDisp.inTitleLine + 1), NO_CLEAR, ML_CENTER);
            else
                vdDispStrCentered(szMerchantName, (obDisp.inTitleLine + 1), NO_CLEAR);
        }

        inResult = pSettleAllHosts(pobTran);
        /**/pdebug(("pSettleAllHosts, inResult = %d", inResult));/**/
    }

    /* Reset execute ZID download after successful settlement of all hosts */
    if (inResult == VS_SUCCESS) {
        if (inGetZIDdownload() == 1)
            inResult = inCallZontalk('F');
        else if (inGetZIDdownload() == 2)
            inResult = inCallZontalk('P');
    } else if (inResult == VS_FAILURE) /* not all hosts settle sucessfully, but some did */
        inResult = VS_SUCCESS;

    /* Add code to display the host response if no printer */
    /* 0 == NOPRINTER; don't include entire header just for 1 value... */
    /* if (inGetTCTPrinterType() == NOPRINTER) */
    if (!fGetEnablePrinter() || (inGetPrinterType() == NOPRINTER)) {
        vdGGRespMsg(szDummyMessage);
        vdDisplayResponseString(szDummyMessage);
    }

    /* Set power failure recovery state */
    inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
    return(inResult);
}

/*********************************************************************************************
* @func int | inClrBatch |
*
*       Clear transctions from batch(s) and update totals, etc.
*       If an individual Host batch is deleted the corresponding
*       transactions from the Open Tab batch are also deleted.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm int     | inClearType |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inClrBatch(TRANSACTION_OBJECT* pobTran,int inClearType,VS_BOOL fDisplayFlag) {
    int inHostIndex;
    unsigned char ucTempHDTRec[SIZE_HDT_REC];
    char szMerchantName[MESSAGE_SIZE + 1];

    if (fDisplayFlag == VS_TRUE && inGetMITTotRecs() > 1) {
        strcpy(szMerchantName, szGetMerchantText());
        if (getgrid() == 0)
            vdDisplayDataStr(szMerchantName, obDisp.inStatusLine, CLR_EOL, ML_LEFT);
        else
            vdDisplayStatusString(szMerchantName);
        vdDelay(SHORT_PROMPT_DELAY);
    }

    /** /pdebug(("--inClrBatch--"));*/
    if (inClearBatch(pobTran, inClearType, fDisplayFlag) != VS_SUCCESS)
        vdDisplayMessageFromFile(BAT_REMOVE_FAIL_ERR_MSG, ERROR_MSG);

    if (inClearType == CLEAR_BATCH) {
        // DO FOR ALL HOSTS
        vdCopyHDTRecFromStruct(ucTempHDTRec);
        for (inHostIndex = 0; inHostIndex < MAX_HOSTS; ++inHostIndex) {
            /* Only print the report for independent host */
            if (!fIsIndependentBatch(inHostIndex))
                continue;
            /* load temporary HDT files will get cleared,
                otherwise the files won't get cleared properly */
            if (inLoadHDTRec(inHostIndex) != VS_SUCCESS) {
                vdDisplayMessageFromFile(HDT_ERR_MSG21, WARNING_MSG);
                return(VS_ERR);
            }
            if (inResetAccum() != VS_SUCCESS)
                vdDisplayMessageFromFile(ACCUM_FAIL_ERR_MSG, ERROR_MSG);

            /* Zero the UTT File */
#ifdef CLERK_DEFINED
            if (inResetUTT(pobTran) != VS_SUCCESS)
                vdDisplayMessageFromFile(UTT_FAIL_ERR_MSG21, ERROR_MSG);


            /* reset active clerk file bb1 */
            if ((inResetADT()) != VS_SUCCESS)
                vdDisplayMessageFromFile(ADT_FILE_ERR_MSG21, ERROR_MSG);
            /* UDT must follow ADT */
            if (inResetUDTLogedIn() != VS_SUCCESS)
                vdDisplayMessageFromFile(UDT_ERR_MSG21, ERROR_MSG);

#endif

            /* Zero the STT File */
#ifdef SHIFT_DEFINED
            if (inResetSTT(pobTran) != VS_SUCCESS)
                vdDisplayMessageFromFile(STT_FAIL_ERR_MSG21, ERROR_MSG);

#endif
        } // end of Host loop
        vdRestoreHDTRecFromStruct(ucTempHDTRec);
    } // End of CLEAR_BATCH
    else {
        if (inResetAccum() != VS_SUCCESS)
            vdDisplayMessageFromFile(ACCUM_FAIL_ERR_MSG, ERROR_MSG);

        /* Zero the UTT File */
#ifdef CLERK_DEFINED
        if (inResetUTT(pobTran) != VS_SUCCESS)
            vdDisplayMessageFromFile(UTT_FAIL_ERR_MSG21, ERROR_MSG);

        /* reset active clerk file bb1 */
        if ((inResetADT()) != VS_SUCCESS)
            vdDisplayMessageFromFile(ADT_FILE_ERR_MSG21, ERROR_MSG);
        /* UDT must follow ADT */
        if (inResetUDTLogedIn() != VS_SUCCESS)
            vdDisplayMessageFromFile(UDT_ERR_MSG21, ERROR_MSG);

#endif

        /* Zero the STT File */
#ifdef SHIFT_DEFINED
        if (inResetSTT(pobTran) != VS_SUCCESS)
            vdDisplayMessageFromFile(STT_FAIL_ERR_MSG21, ERROR_MSG);

#endif
    }

    if (fDisplayFlag == VS_TRUE) {
        vdDisplayMessageFromFile(BAT_DELETED_MSG21, STATUS_MSG);
        vdDelay(SHORT_PROMPT_DELAY);
    }
    return(VS_SUCCESS);
}


/*********************************************************************************************
* @func int | inDeleteAllBatches |
*
*       Delete All Batches.
*       If an individual Host batch is deleted the corresponding
*       transactions from the Open Tab batch are also deleted.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inDeleteAllBatches(TRANSACTION_OBJECT* pobTran) {
    int inCnt;

    /** /pdebug(("--inDeleteAllBatches--"));*/

    for (inCnt = 0; inCnt < inGetMITTotRecs(); inCnt++) {
        vdCloseDCBatch(pobTran);

        /** /pdebug(("inCnt=%d",inCnt));*/
        inLoadMITRec(inCnt);

        if (inDeleteOpenTabBatch(pobTran) != VS_SUCCESS)
            continue;

        if (inClrBatch(pobTran, CLEAR_BATCH, VS_TRUE) == VS_ERR)
            continue;
    }

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inBatchClearOperation |
*
*       Batch Clear Operation - prompts for one or all
*       Hosts to be deleted, deletes batchs as appropriate.
*       If an individual Host batch is deleted the corresponding
*       transactions from the Open Tab batch are also deleted.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

#define     CLEAR_EMPTY         0
#define     CLEAR_ABORT         1
#define     CLEAR_ALL_HOSTS     2
#define     CLEAR_ONE_MERCH     3

int inBatchClearOperation(TRANSACTION_OBJECT* pobTran) {
    signed int inResult = 0;
    int inNumberOfMerchants;
    char chBCOperation = CLEAR_EMPTY;
    char* chNull = 0;


    /** /pdebug (("--inBatchClearOperation--"));*/

    /* If the batch is not empty, continue... */
    if (!fChkAllHostBatches(pobTran) || !fChkAllOpenTabBatches(pobTran) || !fReversalsEmpty()) {
        chBCOperation = CLEAR_ABORT;

        /* Force prompting for merchant selection */
        inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt());

        if (inNumberOfMerchants == 0)
            chBCOperation = CLEAR_ABORT;

        /* clear all hosts for 1 merchant   */
        if (inNumberOfMerchants == 1)
            chBCOperation = CLEAR_ONE_MERCH;

        /* clear all hosts for all merchants */
        if (inNumberOfMerchants > 1)
            chBCOperation = CLEAR_ALL_HOSTS;
    }

    /* Close Tab Batch  opened above by fOpenTabEmpty() */
    vdCloseTabBatch(pobTran);

    if (chBCOperation == CLEAR_ALL_HOSTS || chBCOperation == CLEAR_ONE_MERCH) {
        /* Prompt to confirm */
        if ((inResult = obDisp.inDO_ChooseOne(chNull, (char *) pchGetMsg(CONFIRM_MSG15), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES)
            chBCOperation = CLEAR_ABORT;
    }

    /*
     *      Clear the Batch(es) and/or display error based on
     *      above selections
     */
    switch (chBCOperation) {
    case CLEAR_ONE_MERCH:
        /* delete all hosts for one merch */
        if (inClrBatch(pobTran, CLEAR_BATCH, VS_TRUE) != VS_ERR)
            inResult = VS_SUCCESS;
        vdCloseDCBatch(pobTran);
        inResult = inDeleteOpenTabBatch(pobTran);
        break;
    case CLEAR_ALL_HOSTS:
        /*
         *      Delete all batches for all merchants!
         */
        inResult = inDeleteAllBatches(pobTran);
        break;
    case CLEAR_EMPTY:
        /*
         *      Batch is empty, display error...
         */
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        inResult = VS_SUCCESS;
        break;
    case CLEAR_ABORT:
        inResult = VS_ESCAPE;
        break;
    }

    /*
     *      Check for error during processing
     */
    if (inResult != VS_SUCCESS && inResult != VS_ESCAPE) {

        vdDisplayMessageFromFile(BATCH_ERR_MSG, ERROR_MSG);
        vdDelay(PROMPT_DELAY);
    }

    return(inResult);
} /* end of inBatchClearOperation() */

/*********************************************************************************************
* @func int | inSettleUnadjTipsFunction |
*           Function which runs the function assigned to the function id SETTLE_UNADJUST_TIPS
*
*
* @parm TRANSACTION_OBJECT *| pobTran |
*       Transaction object
*
* @rdesc return values.
* @flag int |  VS_SUCCESS, VS_ERR
* @end
**********************************************************************************************/

int inSettleUnadjTipsFunction(TRANSACTION_OBJECT* pobTran) {
    return(inRunFunction(pobTran, SETTLE_UNADJUST_TIPS));
}


/*********************************************************************************************
* @func int | inSettleUnadjustTips |
*
*       Operation flow function which checks for unadjusted tips in batch.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inSettleUnadjustTips(TRANSACTION_OBJECT* pobTran) {
    int inRetVal = VS_SUCCESS;

    if (fGGAutoSettle() && !fGetUnadjTip()) {
        /* Since the batches are stored only by merchant we don't need */
        /* to look at unadjusted tips per host */


        if (inCheckUnadjustTips(pobTran) == VS_TRUE) {
            vdSGErrorMessage(UNADJUST_TIPS_EXIST_MSG21);
            inRetVal = VS_ESCAPE;
        }
    }

    return(inRetVal);
} /* end func inSettleUnadjustTips() */

/*********************************************************************************************
* @func static int | inCheckUnadjustTips |
*
*       Checks for unadjusted tips in batch.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

static int inCheckUnadjustTips(TRANSACTION_OBJECT* pobTran) {
    int inResult = VS_FALSE;
    int inCurrentBatchRecord;
    int inNumberOfRecordsinBatch;

    /** /pdebug(("--inCheckUnadjustTips--"));*/
    if (!fBatchEmpty(pobTran, VS_FALSE))
        inNumberOfRecordsinBatch = inGetDCBatchRecCnt(pobTran);
    else
        return(VS_ERR);

    inOpenDCBatch(pobTran);

    for (inCurrentBatchRecord = 0; inCurrentBatchRecord < inNumberOfRecordsinBatch; inCurrentBatchRecord++) {
        if (inGetBatchRec(pobTran, inCurrentBatchRecord) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }

        if (inGetTipProcessing() > TIP_OFF && pobTran->srBRec.lnTipAmount == 0L && pobTran->srBRec.inNumberOfTipAdjusts == 0 && !pobTran->srBKey.fVoided && inGGCode() != REFUND && (pobTran->srBRec.inTranCardType != DEBIT_CARD && pobTran->srBRec.inTranCardType != EBT_CARD)) {
            /* Load the HDT so the settlement failed report will reflect */
            /* the correct host */
            inLoadHDTRec(inGetHostHandle());
            inResult = VS_TRUE;
            break;
        }
    }

    inCloseDCBatch(pobTran);

    return(inResult);
} /* end func inCheckUnadjustTips() */


/*********************************************************************************************
* @func int | inPurgeHostFromBatch |
*
*       Delete batch records for a particular host.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
* @parm int *   | inHostNum |
*
* @rdesc Return values.
*
* @flag int    |    - VS_SUCCESS
* @end
**********************************************************************************************/

int inPurgeHostFromBatch(TRANSACTION_OBJECT* pobTran,int inHostNum,VS_BOOL fDisplayFlag) {
    long lnDBWhat,
    lnRecNum,
    lnRetVal;
    BATCH_KEY* psrLocalBKey;
    BATCH_SKEY srBSKey;
    BATCH_REC* psrLocalBRec;
    char szPFDHST[MAX_CONFIG_NM_SIZE + 1];
    char szConfigData[ENV_BUF_SIZE];

    /** /pdebug (("--inPurgeHostFromBatch--"));*/

    if (fDisplayFlag)
        vdDisplayMessageFromFile(DELETING_BATCH_MSG21, STATUS_MSG);

    if (inGetLocalBatchStructures(&psrLocalBKey, &psrLocalBRec) != VS_SUCCESS)
        return VS_ERR;

    /*
     *      Implement Power Fail Recovery
     */
    vdGetMessageFromFile(PFDHST_ENVVAR, szPFDHST);
    sprintf(szConfigData, "%d", inHostNum);
    put_env(szPFDHST, szConfigData, strlen(szConfigData));

    vdBatchDCOpen(pobTran);
    srBSKey.compare_func = inCompareFn; /*inCompFn;*/
    srBSKey.inKeyIdx = KEY_HOST;
    srBSKey.BKey.inBatchHostIndex = inHostNum;

    /*
     *      Locate all records matching inHostNum and delete them
     */
    lnDBWhat = DB_LAST;
    do {
        if ((lnRetVal = lnBatchGetKey(&pobTran->dbBatch, psrLocalBKey, &srBSKey, lnDBWhat, psrLocalBRec, &lnRecNum)) == 1L)
            lnRetVal = db_delete(&pobTran->dbBatch, lnRecNum, 1L);
        lnDBWhat = DB_BACKWARD;
    } while (lnRetVal > 0L);

    inLoadMHTRec(inHostNum);
    vdSetMustClear(VS_FALSE);
    vdSetMustSettleFlag(VS_FALSE);
    inSaveMHTRec(inHostNum);

    /* put_env (szPFDHST, NULL_S, 0); */
    put_env(szPFDHST, "", 0);

    vdFreeLocalBatchStructures(psrLocalBKey, psrLocalBRec);

    /* Remove the reversal and offline files if exist */
    vdReversalsDelete(inHostNum);

    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func VS_BOOL | fReversalsEmpty |
*
*       Checks for the presence of the 3 ISO (PIP Engine) files created
*       when transaction are run through the PIP engine.
*
* @rdesc Return values.
*
* @flag VS_BOOL    |    - VS_TRUE,      If the batch is EMPTY  or DOES NOT exist.
*                       - VS_FALSE,     If batch exists and NOT EMPTY.
* @end
**********************************************************************************************/

VS_BOOL fReversalsEmpty() {
    char stRevFileName[FILENAME_SIZE + 1];
    int inNoMITRecs = inGetMITTotRecs();
    int inCount;
    int inHostIndex;

    /** /pdebug(("--fReversalsEmpty--"));*/


    /** /pdebug (("inNoMITRecs = %d",inNoMITRecs));*/
    for (inCount = 0; inCount < inNoMITRecs; inCount++) {
        inLoadMITRec(inCount);

        for (inHostIndex = 0; inHostIndex < MAX_HOSTS; ++inHostIndex) {
            vdGetReversalFileName(stRevFileName, inHostIndex);
            strcat(stRevFileName, ROC_FILE_EXTN);
            if (inChkFileExist(stRevFileName) == VS_SUCCESS)
                return(VS_FALSE);

            vdGetReversalFileName(stRevFileName, inHostIndex);
            strcat(stRevFileName, OFFLINE_FILE_EXTN);
            if (inChkFileExist(stRevFileName) == VS_SUCCESS)
                return(VS_FALSE);

            vdGetReversalFileName(stRevFileName, inHostIndex);
            strcat(stRevFileName, REVERSAL_FILE_EXTN);
            if (inChkFileExist(stRevFileName) == VS_SUCCESS)
                return(VS_FALSE);
        }
    }
    /** /pdebug(("No Reversals"));*/
    return(VS_TRUE);
}

/*********************************************************************************************
* @func static void | vdReversalsDelete |
*
*       Checks for the presence of and deletes the ROC file, offline transaction file
*       and Reversal file.
*
* @parm  int   | inHostIndex |
*
* @rdesc Return values.
*
* @flag VS_BOOL    |    - VS_TRUE,      If the batch is EMPTY  or DOES NOT exist.
*                       - VS_FALSE,     If batch exists and NOT EMPTY.
* @end
**********************************************************************************************/

void vdReversalsDelete(int inHostIndex) {
    char szRevFileName[FILENAME_SIZE + 1];

    /** /pdebug(("--vdReversalsDelete--"));*/

    vdGetReversalFileName(szRevFileName, inHostIndex);
    strcat(szRevFileName, ROC_FILE_EXTN);
    if (inChkFileExist(szRevFileName) == VS_SUCCESS)
        remove(szRevFileName);

    vdGetReversalFileName(szRevFileName, inHostIndex);
    strcat(szRevFileName, OFFLINE_FILE_EXTN);
    if (inChkFileExist(szRevFileName) == VS_SUCCESS)
        remove(szRevFileName);

    vdGetReversalFileName(szRevFileName, inHostIndex);
    strcat(szRevFileName, REVERSAL_FILE_EXTN);
    if (inChkFileExist(szRevFileName) == VS_SUCCESS)
        remove(szRevFileName);

    vdGetReversalFileName(szRevFileName, inHostIndex);
    strcat(szRevFileName, BACKUP_REV_FILE_EXTN);
    if (inChkFileExist(szRevFileName) == VS_SUCCESS)
        remove(szRevFileName);
}


int SETTLBAT_CODE_CHECK(char* a,char* b,short * c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}



#undef VSSTLBAT_C

#endif // BATCH_DEFINED
